SRC=./src
CFLAGS= -ansi  -pedantic-errors -Wall -Werror 
CFLAGS= -D _GNU_SOURCE
LDFLAGS= -lrt -lpthread
COMPILEONLY= -c 
BIN=bin
OBJ=obj
CM=Common
PB=Public
ST=Static
DN=Dinamic
RL=../$(CM)/$(BIN)/Release

CC=gcc

OBJS = $(SRC)/gserver.o

Debug:   Debug_OR_Release=Debug
Debug:   CFLAGS+=-g 
Debug:   SUBDIRS= ./$(OBJ)/$(Debug_OR_Release) ./$(BIN)/$(Debug_OR_Release)
Debug:   OBJ_F=$(OBJ)/$(Debug_OR_Release)/gserver.o

Release: Debug_OR_Release=Release
Release: CFLAGS+=-DNDEBUG -O2
Release: SUBDIRS= ./$(OBJ)/$(Debug_OR_Release) ./$(BIN)/$(Debug_OR_Release)
Release: OBJ_F=$(OBJ)/$(Debug_OR_Release)/gserver.o
ARCHIVE=iterbintreeKM.a iterlistKM.a libscheduller.a


all: Release

Debug:   create_folders  genericserver Install cleanDebug 
Release: create_folders  genericserver Install cleanRelease




genericserver: show_action  genericserver.obj
	cp  ../$(CM)/$(BIN)/Release/iterbintreeKM.a ./$(BIN)/$(Debug_OR_Release)/
	cp  ../$(CM)/$(BIN)/Release/iterlistKM.a    ./$(BIN)/$(Debug_OR_Release)/
	cp  ../$(CM)/$(BIN)/Release/libscheduller.a ./$(BIN)/$(Debug_OR_Release)/
	ar -x ./$(BIN)/$(Debug_OR_Release)/iterbintreeKM.a
	ar -x ./$(BIN)/$(Debug_OR_Release)/iterlistKM.a
	ar -x ./$(BIN)/$(Debug_OR_Release)/libscheduller.a
	ar -rs  -o ./$(BIN)/$(Debug_OR_Release)/libgenericserver.a  $(OBJ_F)   ./*.o

show_action:
	@echo
	@echo "-----------------------------------"
	@echo "   PRODUCING Generic Server Library"
	@echo "-----------------------------------"
	@echo



genericserver.obj  : $(SRC)/gserver.c $(SRC)/genserver.h $(SRC)/internalgserver.h 
	$(CC)  $(CFLAGS) -I $(SRC) -I ../$(CM)/$(PB)  $(SRC)/gserver.c $(COMPILEONLY) -o $(OBJ_F)

create_folders:
	mkdir -p $(OBJ)/$(Debug_OR_Release) 
	mkdir -p $(BIN)/$(Debug_OR_Release)

Install:creat_instal_folders CopyF CopyHfile 


CopyF: 
	cp $(BIN)/$(Debug_OR_Release)/libgenericserver.a   ../$(CM)/$(BIN)/$(Debug_OR_Release)

CopyHfile:
	cp $(SRC)/genserver.h ../Common/$(PB)
		
creat_instal_folders:
	mkdir -p ../$(CM)/$(PB)
	mkdir -p ../$(CM)/$(BIN)/$(Debug_OR_Release)


cleanDebug:
	for i in $(SUBDIRS); do\
		(cd $$i; rm -f * );\
	done
	rm -f ./*.o
	rm -r $(BIN)
	rm -r $(OBJ)

cleanRelease:
	for i in $(SUBDIRS); do\
		(cd $$i;rm -f *);\
	done
	rm -f ./*.o
	rm -r $(BIN)
	rm -r $(OBJ)

